﻿using System;
using System.Data;
using System.Text;
using System.Collections.Generic;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using System.Data.Common;
namespace Chenxin.Lib.Business.DAL
{
    /// <summary>
    /// 数据访问类t_Intention_CreateInfo。
    /// </summary>
    public class t_Intention_CreateInfo
    {
        public t_Intention_CreateInfo()
        { }
        #region  成员方法

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public static void Add(Chenxin.Lib.Business.Entity.t_Intention_CreateInfo model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into t_Intention_CreateInfo(");
            strSql.Append("RecordId,CreateDate,CreateEmpId,CreateEmp,BelongCityId,BelongCityName,BelongCompanyId,BelongCompany,BelongDepartId,BelongDepart,BelongEmpId,BelongEmp,StartCode,CodeCount,IntentionType,BusinessType)");

            strSql.Append(" values (");
            strSql.Append("@RecordId,@CreateDate,@CreateEmpId,@CreateEmp,@BelongCityId,@BelongCityName,@BelongCompanyId,@BelongCompany,@BelongDepartId,@BelongDepart,@BelongEmpId,@BelongEmp,@StartCode,@CodeCount,@IntentionType,@BusinessType)");
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Business");
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "RecordId", DbType.Guid, model.RecordId);
            db.AddInParameter(dbCommand, "CreateDate", DbType.DateTime, model.CreateDate);
            db.AddInParameter(dbCommand, "CreateEmpId", DbType.Guid, model.CreateEmpId);
            db.AddInParameter(dbCommand, "CreateEmp", DbType.AnsiString, model.CreateEmp);
            db.AddInParameter(dbCommand, "BelongCityId", DbType.Guid, model.BelongCityId);
            db.AddInParameter(dbCommand, "BelongCityName", DbType.AnsiString, model.BelongCityName);
            db.AddInParameter(dbCommand, "BelongCompanyId", DbType.Guid, model.BelongCompanyId);
            db.AddInParameter(dbCommand, "BelongCompany", DbType.AnsiString, model.BelongCompany);
            db.AddInParameter(dbCommand, "BelongDepartId", DbType.Guid, model.BelongDepartId);
            db.AddInParameter(dbCommand, "BelongDepart", DbType.AnsiString, model.BelongDepart);
            db.AddInParameter(dbCommand, "BelongEmpId", DbType.Guid, model.BelongEmpId);
            db.AddInParameter(dbCommand, "BelongEmp", DbType.AnsiString, model.BelongEmp);
            db.AddInParameter(dbCommand, "StartCode", DbType.Int32, model.StartCode);
            db.AddInParameter(dbCommand, "CodeCount", DbType.Int32, model.CodeCount);
            db.AddInParameter(dbCommand, "IntentionType", DbType.Int32, model.IntentionType);
            db.AddInParameter(dbCommand, "BusinessType", DbType.Int32, model.BusinessType);
            db.ExecuteNonQuery(dbCommand);
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public static void Update(Chenxin.Lib.Business.Entity.t_Intention_CreateInfo model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update t_Intention_CreateInfo set ");
            strSql.Append("CreateDate=@CreateDate,");
            strSql.Append("CreateEmpId=@CreateEmpId,");
            strSql.Append("CreateEmp=@CreateEmp,");
            strSql.Append("BelongCityId=@BelongCityId,");
            strSql.Append("BelongCityName=@BelongCityName,");
            strSql.Append("BelongCompanyId=@BelongCompanyId,");
            strSql.Append("BelongCompany=@BelongCompany,");
            strSql.Append("BelongDepartId=@BelongDepartId,");
            strSql.Append("BelongDepart=@BelongDepart,");
            strSql.Append("BelongEmpId=@BelongEmpId,");
            strSql.Append("BelongEmp=@BelongEmp,");
            strSql.Append("StartCode=@StartCode,");
            strSql.Append("CodeCount=@CodeCount,");
            strSql.Append("IntentionType=@IntentionType,");
            strSql.Append("BusinessType=@BusinessType");
            strSql.Append(" where RecordId=@RecordId ");
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Business");
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "RecordId", DbType.Guid, model.RecordId);
            db.AddInParameter(dbCommand, "CreateDate", DbType.DateTime, model.CreateDate);
            db.AddInParameter(dbCommand, "CreateEmpId", DbType.Guid, model.CreateEmpId);
            db.AddInParameter(dbCommand, "CreateEmp", DbType.AnsiString, model.CreateEmp);
            db.AddInParameter(dbCommand, "BelongCityId", DbType.Guid, model.BelongCityId);
            db.AddInParameter(dbCommand, "BelongCityName", DbType.AnsiString, model.BelongCityName);
            db.AddInParameter(dbCommand, "BelongCompanyId", DbType.Guid, model.BelongCompanyId);
            db.AddInParameter(dbCommand, "BelongCompany", DbType.AnsiString, model.BelongCompany);
            db.AddInParameter(dbCommand, "BelongDepartId", DbType.Guid, model.BelongDepartId);
            db.AddInParameter(dbCommand, "BelongDepart", DbType.AnsiString, model.BelongDepart);
            db.AddInParameter(dbCommand, "BelongEmpId", DbType.Guid, model.BelongEmpId);
            db.AddInParameter(dbCommand, "BelongEmp", DbType.AnsiString, model.BelongEmp);
            db.AddInParameter(dbCommand, "StartCode", DbType.Int32, model.StartCode);
            db.AddInParameter(dbCommand, "CodeCount", DbType.Int32, model.CodeCount);
            db.AddInParameter(dbCommand, "IntentionType", DbType.Int32, model.IntentionType);
            db.AddInParameter(dbCommand, "BusinessType", DbType.Int32, model.BusinessType);
            db.ExecuteNonQuery(dbCommand);

        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public static void Delete(Guid RecordId)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from t_Intention_CreateInfo ");
            strSql.Append(" where RecordId=@RecordId ");
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Business");
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "RecordId", DbType.Guid, RecordId);
            db.ExecuteNonQuery(dbCommand);

        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public static Chenxin.Lib.Business.Entity.t_Intention_CreateInfo GetModel(Guid RecordId)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select RecordId,CreateDate,CreateEmpId,CreateEmp,BelongCityId,BelongCityName,BelongCompanyId,BelongCompany,BelongDepartId,BelongDepart,BelongEmpId,BelongEmp,StartCode,CodeCount,IntentionType,BusinessType from t_Intention_CreateInfo ");
            strSql.Append(" where RecordId=@RecordId ");
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Business_Search");
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "RecordId", DbType.Guid, RecordId);
            Chenxin.Lib.Business.Entity.t_Intention_CreateInfo model = null;
            using (IDataReader dataReader = db.ExecuteReader(dbCommand))
            {
                if (dataReader.Read())
                {
                    model = ReaderBind(dataReader);
                }
                dataReader.Close();
                dataReader.Dispose();
            }
            return model;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public static DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select RecordId,CreateDate,CreateEmpId,CreateEmp,BelongCityId,BelongCityName,BelongCompanyId,BelongCompany,BelongDepartId,BelongDepart,BelongEmpId,BelongEmp,StartCode,CodeCount,IntentionType,BusinessType ");
            strSql.Append(" FROM t_Intention_CreateInfo ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Business_Search");
            return db.ExecuteDataSet(CommandType.Text, strSql.ToString());
        }

        /// <summary>
        /// 获得数据列表（比DataSet效率高，推荐使用）
        /// </summary>
        public static List<Chenxin.Lib.Business.Entity.t_Intention_CreateInfo> GetListArray(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select RecordId,CreateDate,CreateEmpId,CreateEmp,BelongCityId,BelongCityName,BelongCompanyId,BelongCompany,BelongDepartId,BelongDepart,BelongEmpId,BelongEmp,StartCode,CodeCount,IntentionType,BusinessType ");
            strSql.Append(" FROM t_Intention_CreateInfo ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            List<Chenxin.Lib.Business.Entity.t_Intention_CreateInfo> list = new List<Chenxin.Lib.Business.Entity.t_Intention_CreateInfo>();
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Business_Search");
            using (IDataReader dataReader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
            {
                while (dataReader.Read())
                {
                    list.Add(ReaderBind(dataReader));
                }
                dataReader.Close();
                dataReader.Dispose();
            }
            return list;
        }


        /// <summary>
        /// 对象实体绑定数据
        /// </summary>
        public static Chenxin.Lib.Business.Entity.t_Intention_CreateInfo ReaderBind(IDataReader dataReader)
        {
            Chenxin.Lib.Business.Entity.t_Intention_CreateInfo model = new Chenxin.Lib.Business.Entity.t_Intention_CreateInfo();
            object ojb;
            ojb = dataReader["RecordId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.RecordId = new Guid(ojb.ToString());
            }
            ojb = dataReader["CreateDate"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.CreateDate = (DateTime)ojb;
            }
            ojb = dataReader["CreateEmpId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.CreateEmpId = new Guid(ojb.ToString());
            }
            model.CreateEmp = dataReader["CreateEmp"].ToString();
            ojb = dataReader["BelongCityId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.BelongCityId = new Guid(ojb.ToString());
            }
            model.BelongCityName = dataReader["BelongCityName"].ToString();
            ojb = dataReader["BelongCompanyId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.BelongCompanyId = new Guid(ojb.ToString());
            }
            model.BelongCompany = dataReader["BelongCompany"].ToString();
            ojb = dataReader["BelongDepartId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.BelongDepartId = new Guid(ojb.ToString());
            }
            model.BelongDepart = dataReader["BelongDepart"].ToString();
            ojb = dataReader["BelongEmpId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.BelongEmpId = new Guid(ojb.ToString());
            }
            model.BelongEmp = dataReader["BelongEmp"].ToString();
            ojb = dataReader["StartCode"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.StartCode = (int)ojb;
            }
            ojb = dataReader["CodeCount"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.CodeCount = (int)ojb;
            }
            ojb = dataReader["IntentionType"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.IntentionType = (int)ojb;
            }
            ojb = dataReader["BusinessType"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.BusinessType = (int)ojb;
            }
            return model;
        }

        #endregion  成员方法
    }
}

